#include "stdafx.h"
#include "Logger.h"

Logger::Logger(void)
{
}

Logger::~Logger(void)
{
}

void Logger::JITCompilationStarted(FunctionID functionId, std::wstring className, std::wstring methodName)
{
	m_Map.insert(std::pair<FunctionID, std::wstring>(functionId, className + L"." + methodName));
}

// Note: "Elt" stands for "Enter/Leave/Tailcall"
void Logger::Method(eMethodEvent methodEvent, FunctionID functionID, int increment)
{
	FuncMapType::iterator iter = m_Map.find(functionID);
	if(iter != m_Map.end())
	{
		switch (methodEvent)
		{
		case ENTER:
			for (int i = 0; i <= m_level; i++)
				wprintf(L" ");
			wprintf(L"<%s>\n", iter->second.c_str());
			m_level = m_level + increment;
			break;
		case LEAVE:
			m_level = m_level + increment;
			for (int i = 0; i <= m_level; i++)
				wprintf(L" ");
			wprintf(L"</%s>\n", iter->second.c_str());
			break;
		case TAILCALL:
			wprintf(L"<%s action=\"tailcall\"/>\n", iter->second.c_str());
			break;
		default:
			break;
		}
	}
}
